﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Baza.EF.DAL;
using Baza.EF.BLL;


namespace Pep_3014_3070_Desktop
{
    public partial class AddCustomer : Form
    {
        public AddCustomer()
        {
            InitializeComponent();
        }

        private void btnOdustani_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void AddCustomer_Load(object sender, EventArgs e)
        {
            cmbGrad.DataSource = DAIznajmljivaciApartmani.SelectCities();
            cmbGrad.DisplayMember = "Name";
        }

        private void btnSpremi_Click(object sender, EventArgs e)
        {
            Customers customer = new Customers();

            customer.FirstName = imeInput.Text.Trim();
            customer.LastName = prezimeInput.Text.Trim();
            customer.Email = emailInput.Text.Trim();



            customer.PasswordSalt = UIHelper.GenerateSalt();
            customer.PasswordHash = UIHelper.GenerateHash(passwordInput.Text, customer.PasswordSalt);


            Address address = new Address();

            Cities city = new Cities();
            city = (Cities)cmbGrad.SelectedItem;

            address.CityID = city.CityID;
            address.StreetNumber = Int32.Parse(BrojUliceInput.Text);
            address.Address1 = Adresa1Input.Text;
            address.Address2 = Adresa2Input.Text;

            DAKorisnici.InsertCustomer(customer);

            MessageBox.Show(Global.GetString("customer_succ"), "Iznajmljivači", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }

    }
}
